<template>
  <div class="login">
    <h2>登录</h2>
    <form @submit.prevent="login">
      <div>
        <label>用户名:</label>
        <input v-model="username" type="text" required>
      </div>
      <div>
        <label>密码:</label>
        <input v-model="password" type="password" required>
      </div>
      <button type="submit">登录</button>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    login() {
      const role = this.username === 'admin' ? 'admin' : 'student'
      localStorage.setItem('user', JSON.stringify({
        username: this.username,
        role: role
      }))
      this.$router.push('/')
    }
  }
}
</script>